import { getBaseUrl } from '@/services/urlconst';
import { requestFunComponFiex } from '@/utils';
import { useRequest } from 'umi';
import { ZF_BJFPJJ, ZF_DDCG, ZF_ZJCG, ZJCG } from '../../Acommon';
import { ApplyManageTab } from '../mconfig/ManageTabSwitch';

const baseUrl = getBaseUrl();

export const applyManageService = (curRes: Record<string, any>) => {
  const getProjectService = () => {
    const request = useRequest(
      (payload: Record<string, any>) => {
        let reqParams = {
          current: 1,
          pageSize: 10,
          sort: 'createTime',
          order: 'desc',
          group: 'applyID,noticeCode',
          state: '100122141010,100122141004',
          unProcureReal: [ZJCG(), ZF_ZJCG(), ZF_DDCG(), ZF_BJFPJJ()]?.join(','),
          ...ApplyManageTab(curRes),
          ...payload,
        };
        let reqUrl = `${baseUrl}/purchaseSourceController/dataApplyGrid/${reqParams?.params}`;
        return requestFunComponFiex('POST', reqUrl, reqParams);
      },
      {
        manual: true,
        paginated: true,
        defaultPageSize: 10,
      },
    );
    return {
      getProjectRun: request.run,
      getProjectLoading: request.loading,
      getProjectPagination: request.pagination,
    };
  };
  return {
    getProjectService,
  };
};

/** 查询所有专家单位信息 */
export const findALLExpertsUnitService = (callback) => {
  const request = useRequest(
    (payload: any) => {
      let reqUrl = `${baseUrl}/expertInfoController/getExpertCompanyName`;
      return requestFunComponFiex('GET', reqUrl, payload);
    },
    {
      manual: true,
      onSuccess: callback,
    },
  );
  return {
    findSourceExpertsRun: request.run,
    findSourceExpertsLoading: request.loading,
    findSourceExpertsData: request?.data?.obj,
  };
};
